new Vue({
  el: '#app',
  data() {
    return {
      form: {
        Data: 'system_info',
        Primary_Key: '',
        Primary_Key_Name: 'System_Name',
        isVague: true,
        page: 1,			//页数
        limit: 10,			//每页数据条数
      },
      data: [{
        id: 1,
        label: '一级 1',
        children: [{
          id: 4,
          label: '二级 1-1',
          children: [{
            id: 9,
            label: '三级 1-1-1'
          }, {
            id: 10,
            label: '三级 1-1-2'
          }]
        }]
      }, {
        id: 2,
        label: '一级 2',
        children: [{
          id: 5,
          label: '二级 2-1'
        }, {
          id: 6,
          label: '二级 2-2'
        }]
      }, {
        id: 3,
        label: '一级 3',
        children: [{
          id: 7,
          label: '二级 3-1'
        }, {
          id: 8,
          label: '二级 3-2'
        }]
      }],
      defaultProps: {
        children: 'children',
        label: 'label'
      },
      total: 0,
      tableData: [],		//表格数据
    }
  },
  mounted() {
    this.getList(this.form)
  },
  methods: {
    onSerach() {				//查询方法
      this.form.page = 1;
      this.getList(this.form)
    },
    
    handleSizeChange(val) {
      this.form.page = 1;
      this.form.limit = val;
      this.getList(this.form)
    },
    handleCurrentChange(val) {
      this.form.page = val;
      this.getList(this.form)
    },
    getList(data) {     //换页方法
      let _this = this
      $.ajax({
        type: 'POST',
        url: `${DomainName}/getTableInquiryAction?token=${$.cookie('token')}`,
        data,
        complete: function (XMLHttpRequest) {
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href = absolutepath() + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        },
        success: function (Result) {
          if (Result.Status == 'success') {
            _this.tableData = Result.tableData
            _this.total = parseInt(Result.limit)
          }
        },
        dataType: "json"
      });
    },
    Add() {
      window.location.href = './Add.html'
    },
    configMember(System_SerialNumber) {
      sessionStorage.setItem("System_SerialNumber", System_SerialNumber)
      window.location.href = './Authority.html?System_SerialNumber=' + System_SerialNumber
    },
    editMember(System_SerialNumber) {
      sessionStorage.setItem("System_SerialNumber", System_SerialNumber)
      window.location.href = './Edit.html?System_SerialNumber=' + System_SerialNumber
    },
    deletMember(System_SerialNumber) {
      this.$confirm('警告！此操作将删除此系统, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(() => {
        this.delete(System_SerialNumber);
      }).catch(() => {
        this.$message({
          type: 'warning',
          message: '已取消删除'
        });
      });
    },
    delete(System_SerialNumber) {
      const _this = this
      $.ajax({
        url: DomainName + '/DeleteAction?token=' + $.cookie('token'),
        type: 'POST',
        data: {
          TableName: 'system_info',
          Primary_Key: System_SerialNumber,
          Primary_Key_Name: 'System_SerialNumber',
          Operation_Name: '删除系统'
        },
        success: function (res) {
          if (res.Status == 'success') {
            _this.getList(_this.form);
            _this.$message({
              type: 'success',
              message: '删除成功!'
            });
          }
        },
        complete: function (XMLHttpRequest) {
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href = absolutepath() + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        }
      })
    }
  },
})